package com.logbug.designpatterns;

public class TestTemplateAndChain {
    static abstract class Leader {
        private Leader nextLeader;

        public void setNextLeader(Leader nextLeader) {
            this.nextLeader = nextLeader;
        }

        public void handleRequest(int leaveDays) {
            if (leaveDays < getMaxLeaveDays()) {
                System.out.println("请假" + leaveDays + "天，被 " + getLeaderName() + " 批准。");
            } else {
                if (nextLeader != null) {
                    nextLeader.handleRequest(leaveDays);
                } else {
                    System.out.println("请假" + leaveDays + "天，天数太多，不被批准。");
                }
            }
        }

        public abstract int getMaxLeaveDays();

        public abstract String getLeaderName();


    }

    static class Teacher extends Leader {


        @Override
        public int getMaxLeaveDays() {
            return 2;
        }

        @Override
        public String getLeaderName() {
            return "老师";
        }
    }

    static class HeaderTeacher extends Leader {
        @Override
        public int getMaxLeaveDays() {
            return 5;
        }

        @Override
        public String getLeaderName() {
            return "班主任";
        }
    }

    public static void main(String[] args) {
        Leader teacher = new Teacher();
        Leader headerTeacher = new HeaderTeacher();
        teacher.setNextLeader(headerTeacher);
        teacher.handleRequest(1);
        teacher.handleRequest(4);
        teacher.handleRequest(6);

    }

}
